package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.backend.entity.PingJia;
import com.example.backend.entity.vo.PingFenVo;
import com.example.backend.entity.vo.SJPLQ;
import com.example.backend.entity.vo.UserVo;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public interface PingJiaMapper extends BaseMapper<PingJia> {
    /**根据商家id查询当天评价*/
    @Select("select * from wm_pj where sjid = #{sjid} and Date(pjsj) = CURDATE()")
    List<PingJia> querypj(Integer sjid);
    /**
     * 获取商家评分
     */
    @Select("select ROUND(AVG(sjpf), 2) from wm_pj where sjid = #{sjid}")
    Double getAVGPinFen(Integer sjid);

    @Select("select * from wm_pj where sjid = #{sjid}")
    ArrayList<PingJia> getPinJias(Integer sjid);

    @Select("select yhsf,count(*) as count from wm_sf group by yhsf")
    ArrayList<UserVo> getUserType();

    @Select("select sjpf,count(*) as count from wm_pj group by sjpf")
    ArrayList<PingFenVo> getPingFen();

    @Select("select sjpf,count(*) as count from wm_pj where sjid = #{sjid} group by sjpf")
    List<PingFenVo> getPingFenBySjid(Integer sjid);

    @Select("select pj.pjid, sf.yhnc, sf.yhtx, cp.cpmc, cp.cpbq, pj.sjpf, pj.pjsj, pj.pjnr, pj.sctp, pj.hfsj, pj.sjhf from wm_pj pj join wm_dd dd on pj.ddid = dd.ddid join wm_sf sf on sf.yhid = dd.yhid join wm_xq xq on xq.ddid = dd.ddid join wm_cp cp on cp.cpid = xq.cpid join wm_sj sj on sj.sjid = dd.sjid where pj.sjid = #{sjid} ")
    List<SJPLQ> getSJPLQ(Integer sjid);
}
